package articles.controller;

import java.io.IOException;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.xml.internal.bind.v2.runtime.Name;

import articles.data.QnAPersistenceManager;
import articles.model.Articles;

@SuppressWarnings("serial")
public class ShowArticlesCrawServlet extends HttpServlet {
		public void doGet(HttpServletRequest req, HttpServletResponse resp)
				throws IOException {
			resp.setContentType("text/plain");
			resp.getWriter().println("Hello, world");
			
			String str=req.getParameter("name"); 
			
			if(str!=null)
			{
				int name = Integer.parseInt(str);  
				
				PersistenceManager psm = QnAPersistenceManager.get().getPersistenceManager();
				Query query_article = psm.newQuery(Articles.class);
				query_article.setFilter("vodeNo == "+name);
				query_article.setOrdering("date desc");
				query_article.setRange(0,6);
				@SuppressWarnings({ "unchecked" })
				List<Articles> listArticles = (List<Articles>) query_article.execute();
				req.setAttribute("listArticles", listArticles);
				try {
					req.getRequestDispatcher("/show_articles_craw.jsp").forward(req, resp);
				} catch (ServletException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
}
